package com.knife.blog.logic.impl;

import java.util.Collection;
import java.util.Date;
//import com.knife.blog.domain.BlogCircle;
import com.knife.blog.domain.BlogInfo;
import com.knife.blog.domain.BlogNewsDoc;
import com.knife.blog.logic.BlogCircleDocService;
import com.knife.util.CommUtil;
import com.knife.web.tools.DbPageList;
import com.knife.web.tools.IPageList;

public class BlogCircleDocServiceImpl extends DAOSupportService 
		implements BlogCircleDocService {
	
	private static BlogCircleDocServiceImpl circleDocService = new BlogCircleDocServiceImpl();
	
	public static BlogCircleDocServiceImpl getInstance(){
		return circleDocService;
	}

	public IPageList getTopDoc(BlogInfo circle, String dirId, Date date1, Date date2,
			String orderBy,int status, int elite, int currentPage,int pageSize) {
		// TODO 自动生成方法存根
		//String scope = "cid in ( select docId as cid from BlogCircleNewsDoc where 1=1 ";
		String scope = "1=1";
		java.util.Collection<Object> paras = new java.util.ArrayList<Object>();
		//paras.add(circle.getCid());
		/*if (username != null && (!"".equals(username))) {
			scope += "and circleId in(select parentId as circleId from BlogCircleMember where username=?) ";
			paras.add(username);
		}*/
		if (elite > 0) {
			scope += " and elite=?";
			paras.add(elite);
		}
		if (circle != null) {
			scope += " and circlesn=?";
			paras.add(circle.getCid());
		}
		if (status > 0) {
			scope += "status>=" + status;
		}
		//scope += ")";
		if (date1 != null) {
			scope += " and displaytime>=?";
			paras.add(date1);
		}
		if (date2 != null) {
			scope += " and displaytime<?";
			paras.add(date2);
		}
		if (!CommUtil.hasLength(orderBy))
			scope += " order by displaytime desc";
		else
			scope += " order by " + orderBy + " desc";
		DbPageList pList = new DbPageList(BlogNewsDoc.class, scope, paras);
		pList.doList(currentPage, pageSize);
		return pList;
	}

	public IPageList queryDoc(String scope , Collection paras, int currentPage, int pages) {
		// TODO 自动生成方法存根
		DbPageList pList = new DbPageList(BlogNewsDoc.class,scope,paras);
		pList.doList(currentPage, pages);
		return pList;
	}
	
	public IPageList queryTopDocByUser(String username, int currentPage, int pages){
		String scope = "circlesn in(select cid from bloginfo where inputuser=?) " +
				"or circlesn in(select sn as circlesn from blogcirclemember where username=?) " +
				"order by inputtime desc";
		java.util.Collection<Object> paras = new java.util.ArrayList<Object>();
		paras.add(username);
		paras.add(username);
		//paras.add(username);
		DbPageList pList = new DbPageList(BlogNewsDoc.class,scope,paras);
		pList.doList(currentPage, pages);
		return pList;
	}

	public IPageList queryTopDoc(String scope, int elite, 
			int lastInput, int currentPage,int pages) {
		// TODO 自动生成方法存根
		return null;
	}

	public boolean setRecommend(String cid) {
		// TODO 自动生成方法存根
		return false;
	}

	public BlogNewsDoc getCircleDoc(String cid) {
		// TODO 自动生成方法存根
		BlogNewsDoc doc = (BlogNewsDoc)this.dao.get(BlogNewsDoc.class, cid);
		return doc;
	}

	public IPageList getTopDoc(BlogInfo circle,String orderBy, int i, int j) {
		// TODO 自动生成方法存根
		return getTopDoc(circle,"",null,null,orderBy,0,0,i,j);
	}

	/*public IPageList getTopDoc(BlogCircle circle, 
			Date d1, Date d2, String orderBy, int i, int j) {
		// TODO 自动生成方法存根
		return null;
	}*/

	public IPageList getEliteDoc(BlogInfo circle,String orderBy, int elite, int i, int j) {
		// TODO 自动生成方法存根
		return getTopDoc(circle,"",null,null,"",0,elite,i,j);
	}

}
